<template>
	<view>
		<w-list :list='homeList' text='请完善信息' :status='status'>
			<template>
				<view v-for="(item,index) in homeList" :key="index">
					<w-home-list :item='item'></w-home-list>
				</view>
			</template>
		</w-list>
	</view>
</template>

<script>
	import {
		getBuildByArea,
		getUnitByBuild,
		getDictListByType,
		getHouseByUnit
	} from '@/api/index.js'
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState(['userInfo'])
		},
		onLoad() {
			this.form = {
				name: this.userInfo.name,
				mobile: this.userInfo.mobile,
				userType: this.userInfo.userType,
			}
			if (this.userInfo.house && this.userInfo.house.id) {
				getHouseByUnit({
					unitId: this.userInfo.unit.id
				}).then(res => {
					res.map(item => {
						if (item.id == this.userInfo.house.id) {
							this.form = {
								...this.form,
								houseName: item.no,
								houseId: item.id,
								master:item.name
							}
						}
					})
				})
			}
			if (this.userInfo.unit && this.userInfo.unit.id) {
				getUnitByBuild({
					building: this.userInfo.building.id
				}).then(res => {
					res.map(item => {
						if (item.id == this.userInfo.unit.id) {
							this.form = {
								...this.form,
								unitName: item.name,
								unitId: item.id
							}
						}
					})
				})
			}
			if (this.userInfo.area && this.userInfo.area.id) {
				getBuildByArea({
					areaId: this.userInfo.area.id
				}).then(res => {
					res.map(item => {
						this.form = {
							...this.form,
							areaName: item.area.name,
							areaId: item.area.id
						}
						if (this.userInfo.building && this.userInfo.building.id) {
							if (item.id == this.userInfo.building.id) {
								this.form = {
									...this.form,
									buildingName: item.name,
									buildingId: item.id,
								}
							}
						}
					})
				})
			}
			getDictListByType({
				type: 'userType'
			}).then(res => {
				this.userTypeSelector = res
				if (this.userInfo.userType) {
					this.userTypeSelector.map(item => {
						if (item.value == this.userInfo.userType) {
							this.form = {
								...this.form,
								userTypeName: item.label,
							}
						}
					})
				}
			})
		},
		watch: {
			form: {
				handler(val, oldVal) {
					console.log(val)
					if(val.houseName){
						this.homeList = [val]
					}
				},
				deep: true
			}
		},
		data() {
			return {
				homeList: [],
				status: 'nomore',
				form: {}
			}
		},
		methods: {

		}
	}
</script>

<style>

</style>
